/**
* @file init_callback_manager.h
*
* Copyright (c) Huawei Technologies Co., Ltd. 2025. All Rights reserved.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

#ifndef ASCEND_RUNTIME_INIT_CALLBACK_MANAGER_H_
#define ASCEND_RUNTIME_INIT_CALLBACK_MANAGER_H_

#include <map>
#include <mutex>
#include "acl_rt.h"

namespace acl {
class ACL_FUNC_VISIBILITY InitCallbackManager {
   public:
    static InitCallbackManager &GetInstance();

    aclError RegInitCallback(aclRegisterCallbackType type, aclInitCallbackFunc cbFunc, void *userData);
    aclError UnRegInitCallback(aclRegisterCallbackType type, aclInitCallbackFunc cbFunc);
    aclError NotifyInitCallback(aclRegisterCallbackType type, const char *configStr, size_t len);

    aclError RegFinalizeCallback(aclRegisterCallbackType type, aclFinalizeCallbackFunc cbFunc, void *userData);
    aclError UnRegFinalizeCallback(aclRegisterCallbackType type, aclFinalizeCallbackFunc cbFunc);
    aclError NotifyFinalizeCallback(aclRegisterCallbackType type);

   private:
    InitCallbackManager();
    ~InitCallbackManager() = default;
    InitCallbackManager(const InitCallbackManager &other) = delete;
    InitCallbackManager &operator=(const InitCallbackManager &other) = delete;
    InitCallbackManager(const InitCallbackManager &&other) = delete;
    InitCallbackManager &operator=(const InitCallbackManager &&other) = delete;

   private:
    std::multimap<aclRegisterCallbackType, std::pair<aclInitCallbackFunc, void*>> initCallbackMap_;
    std::multimap<aclRegisterCallbackType, std::pair<aclFinalizeCallbackFunc, void*>> finalizeCallbackMap_;
    std::recursive_mutex &mutex_;
};
}

#endif  //ASCEND_RUNTIME_INIT_CALLBACK_MANAGER_H_
